package com.zzg.demo.springbatch.demo.customer;

import com.zzg.demo.springbatch.demo.bean.PersonEntity;
import lombok.extern.slf4j.Slf4j;
import org.springframework.batch.core.ItemWriteListener;
import org.springframework.batch.item.Chunk;

@Slf4j
public class MyWriteListener implements ItemWriteListener<PersonEntity> {
    @Override
    public void beforeWrite(Chunk<? extends PersonEntity> items) {
        log.error(String.format("MyWriteListener-beforeWrite-itemSize:%s", items.size()));
    }

    @Override
    public void afterWrite(Chunk<? extends PersonEntity> items) {
        log.error(String.format("MyWriteListener-afterWrite-itemSize:%s", items.size()));
    }

    @Override
    public void onWriteError(Exception ex, Chunk<? extends PersonEntity> items) {
        log.error(String.format("MyWriteListener-onWriteError-%s", ex.getMessage()));
        for (PersonEntity message : items) {
            log.error(String.format("MyWriteListener-Failed writing : %s", message.toString()));
        }
    }
}
